<template>
  <dt-modal-edit
    ref="modal"
    title="编辑"
    :label-width="110"
    :width="500"
    @ok="onOk"
    :loading="loading"></dt-modal-edit>
</template>

<script>
  import Opt from '../opt/UpdateOpt.js'
  import mgr from '@/biz/backStage/appMenuConfig.js'

  export default {
    data() {
      return {
        info: {},
        callback: null,
        loading: false
      }
    },
    mounted() {},
    methods: {
      show(info, callback) {
        this.info = {
          mark: 0,
          ...info,
          menuIcon: info.menuIcon
            ? [
                {
                  url: info.menuIcon,
                  name: ''
                }
              ]
            : []
        }
        this.callback = callback
        this.$refs.modal.show(new Opt(this.info))
      },
      hide() {
        this.$refs.modal.hide()
      },
      onOk() {
        this.loading = true
        let url = this.info.id ? 'update' : 'insert'
        console.log(this.info)
        mgr[url]({
          menuName: this.info.menuName,
          menuCode: this.info.menuCode,
          sort: this.info.sort,
          mark: this.info.mark,
          menuIcon: this.info.menuIcon.length ? this.info.menuIcon[0].url : '',
          type: this.info.type,
          id: this.info.id
        })
          .then((res) => {
            this.callback()
            this.hide()
            this.loading = false
          })
          .catch((err) => {
            this.loading = false
          })
      }
    }
  }
</script>

<style lang="scss" scoped></style>
